package win.timloong.android.carwiki.adapter;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import win.timloong.android.carwiki.R;
import win.timloong.android.carwiki.bean.Quanzi;
import win.timloong.android.carwiki.util.ImageUtil;

/**
 * Created by tim on 16/7/12.
 */

public class QuanziAdapter extends RecyclerView.Adapter<QuanziAdapter.Holder> {
    private ArrayList<Quanzi> arrayList = new ArrayList<>();
    Quanzi quanzi;
    public  QuanziAdapter(ArrayList list){
        arrayList = list;
    }

    public  void addData(ArrayList data){
        arrayList.addAll(data);
        notifyDataSetChanged();
    }
    public  void addData(Quanzi data){
        arrayList.add(data);
        notifyDataSetChanged();
    }


    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_quanzi_item,parent,false));
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {

        quanzi = arrayList.get(position);
        ImageUtil.loadImage(quanzi.getLogo(),holder.logo);
        holder.name.setText(quanzi.getName());
        holder.time.setText(quanzi.getTime());
        holder.fabiao.setText(quanzi.getFabiao());
        holder.gridView.setAdapter(new QuanziItemAdapter(quanzi.getUrls()));
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    class  Holder extends  RecyclerView.ViewHolder{
        ImageView logo;
        TextView name;
        TextView time;
        TextView fabiao;
        GridView gridView;

        public Holder(View convertView) {
            super(convertView);
            logo= (ImageView) convertView.findViewById(R.id.quanzi_item_logo);
            name = (TextView) convertView.findViewById(R.id.quanzi_item_name);
            time = (TextView) convertView.findViewById(R.id.quanzi_item_time);
            fabiao = (TextView) convertView.findViewById(R.id.quanzi_item_fabiao);
            gridView = (GridView) convertView.findViewById(R.id.quanzi_item_gridview);
            gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
        }
    }
}
